package dy.com.part1.chapter3;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class Interrupt {
    public static void main(String[] args) throws InterruptedException {
        IntStream.range(1,3).forEach(System.out::println);
        List<String> a=new ArrayList<String>();
        a.add("123");
        a.add("456");
        a.forEach(System.out::println);

        Thread t1 = new Thread(()->{
//            try {
//                TimeUnit.MINUTES.sleep(1);
//
//            } catch (InterruptedException e) {
//                System.out.println("我被打断了,我不睡了"+Thread.currentThread().isInterrupted());;
//            }
//            int i =20;
            while(true){
                if(Thread.currentThread().isInterrupted()){
                    System.out.println("我被打断了");
                    break;
                }
            }
        });
        t1.start();

        TimeUnit.SECONDS.sleep(2);
        System.out.println(t1.isInterrupted());
        t1.interrupt();
        System.out.println(t1.isInterrupted());
        t1.interrupt();
    }
}
